<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加电影</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios0.18.js"></script>
</head>
<body>
<div id="app">
    <form @submit.prevent="submitForm">
        电影名：<input type="text" v-model="mname" required>
        时长：<input type="number" v-model="mtime" required>
        选择海报：<input type="file" @change="selfile" required>
        <input type="submit" value="上传">
    </form>
</div>

</body>
</html>
<script>
    new Vue({
        el: "#app",
        data: {
            mname: '',
            mtime: '',
            imgFile: ''
        },
        methods: {
            selfile(event) {
                this.imgFile = event.target.files[0];
            },
            submitForm() {
                const formData = new FormData();
                formData.append("movieName", this.mname);
                formData.append("movieTime", this.mtime);
                formData.append("file", this.imgFile);
                axios.post("http://localhost:8080/ssm/admin/addMovie",
                    formData).then(function (resp) {
                    console.log(resp.data);
                    if (resp.data.code === 200) {
                        alert("上传成功");
                    } else {
                        alert(resp.data.msg);
                    }
                });
            }
        }
    })
</script>
